package com.jzh.cmhSystem.biz.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jzh.cmhSystem.biz.UserAndDetailService;
import com.jzh.cmhSystem.entity.UserAndDetail;
import com.jzh.cmhSystem.mapper.UserAndDetailMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserAndDetailServiceImpl implements UserAndDetailService {
    @Autowired
    private UserAndDetailMapper userAndDetailMapper;


    @Override
    public List<UserAndDetail> getUserListByRoleAndName(String nickname, String phone, String name, String role, Integer enterpriseId) {
        UserAndDetail userAndDetail = new UserAndDetail();
        userAndDetail.setNickname(nickname.trim());
        userAndDetail.setPhone(phone.trim());
        userAndDetail.setName(name.trim());
        userAndDetail.setEnterpriseId(enterpriseId);
        System.out.println(userAndDetail);
        return userAndDetailMapper.selectUserList(userAndDetail);
    }

    @Override
    public List<UserAndDetail> getUserEnListByRoleAndName(String nickname, String phone, String name, String role, Integer enterpriseId) {
        UserAndDetail userAndDetail = new UserAndDetail();
        userAndDetail.setRole(Integer.parseInt(role));
        userAndDetail.setNickname(nickname.trim());
        userAndDetail.setPhone(phone);
        userAndDetail.setName(name.trim());
        userAndDetail.setEnterpriseId(enterpriseId);
        return userAndDetailMapper.selectEnUserList(userAndDetail);
    }

    @Override
    public void addDetail(UserAndDetail userAndDetail) {
        userAndDetailMapper.insert(userAndDetail);
    }

    @Override
    public List<UserAndDetail> getEnUserByUserId(int id) {
        return userAndDetailMapper.selectEnUserByUserId(id);
    }

    @Override
    public List<UserAndDetail> getUserDetailByUserId(int id) {
        return userAndDetailMapper.selectUserById(id);
    }

    @Override
    public void updateInfo(UserAndDetail userAndDetail) {
        userAndDetailMapper.updateUserDetailByUserId(userAndDetail);
    }

    @Override
    public void updateInfoById(UserAndDetail userAndDetail) {
        System.out.println(userAndDetail);
        userAndDetailMapper.updateById(userAndDetail);
    }

    @Override
    public void deleteUserDetailById(UserAndDetail userAndDetail) {
        QueryWrapper<UserAndDetail> queryWrapper = new QueryWrapper();
//        queryWrapper.like(StringUtils.isNotBlank(name), "username", username);
        queryWrapper.eq("user_id", userAndDetail.getUserId());
        userAndDetailMapper.delete(queryWrapper);
    }


}
